import sys
import os
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QFontDatabase
from PySide6.QtCore import Qt
from app.ui.main_window import MainWindow
from app.data.database import db
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QFontDatabase
from PySide6.QtCore import Qt
import sys
import os


def main():
    """应用程序主入口点"""
    app = QApplication(sys.argv)
    app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)

    # 加载字体文件
    font_path = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), "STXingkai.ttf"
    )
    if os.path.exists(font_path):
        QFontDatabase.addApplicationFont(font_path)
    else:
        print(f"警告：找不到字体文件：{font_path}")

    window = MainWindow()
    window.show()

    exit_code = app.exec()
    db.close()  # 确保在程序退出时关闭数据库连接
    sys.exit(exit_code)


if __name__ == "__main__":
    main()
